package com.copyctrl.admin.controller;

import com.copyctrl.admin.service.UserService;
import com.copyctrl.campus.common.model.ApiResponse;
import com.copyctrl.model.CampUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author:JH
 * @version:1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("/all")
    public ApiResponse getAllUser(){
        List<CampUser> all = userService.findAll();
        return ApiResponse.ofSuccess(all);
    }
    @PostMapping("/{message}/{id}")
    public ApiResponse sendMessage(@PathVariable String message,@PathVariable String id){
        try {
            int i=userService.sendMessage(message,id);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return ApiResponse.ofSuccess("ok");
    }
}
